<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    //100.00%
    var pivotIndex = function(nums) {
        const len = nums.length;
        let sum = nums.reduce((pre,cur)=>pre+cur,0);
        let leftSum = 0;
        for(let i=0; i<len; i++){
            if(leftSum == sum - leftSum - nums[i])return i;
            leftSum += nums[i];
        }
        return -1;
    };
    let nums = [1,7,3,6,5,6];
    console.log(pivotIndex(nums));
    
</script>
</html>